﻿/// <reference path="../game/fourkill.util.js" />
/// <reference path="../painters/fourkill.painter.singletons.js" />
/// <reference path="../objects/fourkill.object.singletons.js" />
/// <reference path="../input/fourkill.input.singletons.js" />

var LoginView = Base.extend({
    initialize: function initialize(host) {
        this.host = host;
        this.$loginDiv = null;
        this.$loginButton = null;
        this.$emailInput = null;
        this.$title = null;
        this.$passwordInput = null;
        this.inputs = [];
        this.viewId = "login";
        this.isActive = false;
        this.paintInterval = null;
        this.frameRate = 100;
        this.bounce = 0;
        this.bounceOffset = 1;
        this.color = 255;
        this.colorOffset = -10;
    },
    setup: function setup() {
        var self = this;

        this.$loginDiv = $("#loginDiv");
        var d = this.$loginDiv;
        d.offset({ top: (parseInt($(window).height() - 230) / 2), left: parseInt(($(window).width() - 430) / 2) });

        this.$title = d.find(".login-title");
        this.$loginButton = d.find("#loginBtn");
        this.$emailInput = d.find("#emailTxt");
        this.$passwordInput = d.find("#passwordPwd");
        this.$loginButton.click(function (e) {
            self.host.notify("login", { email: self.$emailInput.val(), password: self.$passwordInput.val(), targetView: "fourkill" });
        });

        d.show();

        /*for (var k = 0; k < this.inputs.length; k++) {
            if (this.inputs[k].isAvailable()) {
                this.inputs[k].enable();
            }
        }*/
        this.paintInterval = setInterval((function (self) { return function () { self.paint(); } })(this), this.frameRate);

        this.isActive = true;
    },
    teardown: function teardown() {
        /*for (var k = 0; k < this.inputs.length; k++) {
            if (this.inputs[k].enabled) {
                this.inputs[k].disable();
            }
        }*/
        if (this.paintInterval != null) {
            clearInterval(this.paintInterval);
            this.paintInterval = null;
        }
        this.$loginDiv.hide();
        this.isActive = false;
    },
    pause: function pause() {
    },
    resume: function resume() {
    },
    resize: function resize() {
        if (this.isActive) {
            var d = this.$loginDiv;
            d.offset({ top: (parseInt($(window).height() - 230) / 2), left: parseInt(($(window).width() - 430) / 2) });
        }
    },
    paint: function paint() {
        this.color += this.colorOffset;
        this.bounce += this.bounceOffset;
        if (this.color <= 175 || this.color >= 255) this.colorOffset *= -1;
        if (this.bounce >= 12 || this.bounce <= 0) this.bounceOffset *= -1;
        var rand = util.random(50);
        if (rand == 25) {
            this.$title.css("font-weight", "normal");
            this.$title.css("color", "red");
        }
        else {
            this.$title.css("font-weight", "bold");
            this.$title.css("color", "rgb(" + this.color + "," + this.color + "," + this.color + ")");
        }
        this.$title.css("letter-spacing", "" + this.bounce + "px");
    }
});
